﻿using DevExpress.Data.Filtering;
using DevExpress.Xpo.DB;

namespace EasyXaf.FullTextSearch;

public class FullTextContainsFunction : ICustomFunctionOperatorFormattable
{
    public string Name => "FullTextContains";

    public object Evaluate(params object[] operands)
    {
        throw new NotImplementedException();
    }

    public Type ResultType(params Type[] operands)
    {
        return typeof(bool);
    }

    public string Format(Type providerType, params string[] operands)
    {
        if (providerType == typeof(MSSqlConnectionProvider))
        {
            return string.Format("CONTAINS({0},{1})", operands[0], operands[1]);
        }
        else if (providerType == typeof(MySqlConnectionProvider))
        {
            return string.Format("MATCH({0}) AGAINST ({1} IN BOOLEAN MODE)", operands[0], operands[1]);
        }
        throw new NotSupportedException(string.Concat("This provider is not supported: ", providerType.Name));
    }
}
